﻿using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace OMS.Infrastructure
{
    public class ExceptionHandlerActionFilter : ActionFilterAttribute, IExceptionFilter
    {
        private static Logger log = NLog.LogManager.GetCurrentClassLogger();

        void IExceptionFilter.OnException(ExceptionContext exceptionContext)
        {
            log.Error(exceptionContext.Exception.Message, exceptionContext.Exception);
            exceptionContext.Result = new RedirectToRouteResult(new RouteValueDictionary
            {
                {"controller", "Home"},
                {"action", "OnError"}
            });
            exceptionContext.ExceptionHandled = true;
            //ec.HttpContext.Response.Clear();
            //ec.HttpContext.Response.StatusCode = 401;
        }
    }
}